<template>
    <div>

<el-card style>
<el-form inline>
            <!-- <el-form-item label="简称:" class="mgb-0">
              <el-input v-model="fname"></el-input>
            </el-form-item>
            <el-form-item label="编码:" class="mgb-0">
              <el-input v-model="fnumber"></el-input>
            </el-form-item> -->
            <el-row>

<el-col :span="12">

  <el-form-item label="业务日期:" class="mgb-0">
      <el-date-picker
      v-model="value1"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      value-format="yyyy-MM-dd HH:mm:ss">
    </el-date-picker>
            </el-form-item>
    
</el-col>
<el-col :span="8">
<el-form-item label="生产单编码:" class="mgb-0">
              <el-input v-model="fnumber"></el-input>
            </el-form-item>
</el-col>
          <el-col :span="4">
<el-form-item class="mgb-0">
              <el-button type="primary" icon="el-icon-search" @click="searchData"></el-button>
              <el-button type="success" icon="el-icon-refresh" @click="clearData"></el-button>
            </el-form-item>
            </el-col>
            </el-row>
          </el-form>

</el-card>
       
        
<el-card style="margin-top: 10px">
         <div>
    <div style="margin-bottom: 10px">
        <el-button type="success" @click="openAdd" >新建</el-button>
        <el-button type="primary" @click="batchSh">审核</el-button>
        <el-button type="warning" @click="batchZc" >反审核</el-button>
        <el-button type="primary" @click="batchXd">下达</el-button>
        <el-button type="primary" @click="ReqMaterial()">领料</el-button>
        <el-button type="primary" @click="reportMaterial()">汇报</el-button>
        <el-button type="primary" @click="instoreMaterial()">入库</el-button>
        <el-button type="danger" @click="closereason()">关闭</el-button>
        <el-button type="danger" @click="remove()">删除</el-button>
        </div>

<el-dialog title="关闭原因" :visible.sync="dialogVisible">
        <span>
<el-input
            v-model="fclosereason"
            type="textarea"
            :rows="2"
            placeholder="请输入关闭原因"
          />
          </span>
          <span  slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitclosereason()">提交</el-button>
          <el-button @click="closeDialog()" type="danger">关闭</el-button>
          </span>
      </el-dialog>

      <el-dialog title="领料信息" :visible.sync="reqMaterialDialog" width="100vw" v-if="reqMaterialDialog" >
        <span>
          <el-card>
  <el-form label-width="100px" :model="materialData" :rules="rules">
<el-row>
  <el-col :span="12">
            <el-form-item label="原料批号:" prop="freqlot" >
                <el-input v-model="materialData.freqlot"></el-input>
            </el-form-item>
          </el-col>
   <el-col :span="12">
            <el-form-item label="原料名称:" prop="fmaterialid" >
              <inputSelect v-model="materialData.fmaterialid" :f7Param="MaterialF7Param" 
                    :loadShow="materialData.fmaterialname" 
                    title="原料信息表"
                   ></inputSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
         <el-col :span="12">
            <el-form-item label="领料数量:" prop="freqqty" id="freqqty" >
                <el-input v-model="materialData.freqqty" :min="0" type="number"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="领料时间:" prop="fbizdate" >
                <el-date-picker v-model="materialData.fbizdate" type="datetime"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="生产订单ID:" prop="fworkorderid" v-if="false">
                <el-input v-model="materialData.fworkorderid"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="生产订单行ID:" prop="fworkorderentryid" v-if="false">
                <el-input v-model="materialData.fworkorderentryid"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="领料单编码:" prop="fnumber" >
                <el-input v-model="materialData.fnumber" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-table border :data="entryList" v-loading="tableLoading" ref="iTable2" @row-click="entryhandleRowClick">
            <el-table-column align="center" type="selection" width="55"></el-table-column>
            <el-table-column label="订单ID" prop="fid" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="生产批号" prop="flot" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialnumber" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialmodel" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="计量单位" prop="funitname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计产量" prop="fqty" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计完工时间" prop="fplanenddate" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="领料数量" prop="freqqty" align="center" show-overflow-tooltip></el-table-column>
          </el-table>
        </el-row>

  </el-form> 
          </el-card>
          </span>
          <span  slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitReqMaterialDialog()">提交</el-button>
          <el-button @click="closeReqMaterialDialog(materialData)" type="danger">关闭</el-button>
          </span>
      </el-dialog>

      <el-dialog title="汇报信息" :visible.sync="reportDialog" width="100vw"  v-if="reportDialog">
        <span>
          <el-card>
  <el-form label-width="100px" :model="reportData" :rules="rules">
<el-row>
  <el-col :span="6">
<el-form-item label="设备" prop="fmachineid" >
              <inputSelect v-model="reportData.fmachineid" :f7Param="machineF7Param" 
                    :loadShow="reportData.fmachinenumber" 
                    title="设备信息表"
                     @onF7DaTaSelected="onF7MachineSelected"
                   ></inputSelect>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="设备名称" prop="fmachinename" >
                <el-input v-model="reportData.fmachinename" disabled></el-input>
            </el-form-item>
          </el-col>
          
          <el-col :span="6">
            <el-form-item label="模具编号" prop="fmodid" >
              <inputSelect v-model="reportData.fmodid" :f7Param="modF7Param" 
                    :loadShow="reportData.fmodnumber" 
                    title="模具信息表"
                     @onF7DaTaSelected="onF7ModSelected"
                   ></inputSelect>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="模穴数" prop="fmodcavity" >
                <el-input v-model="reportData.fmodcavity" disabled></el-input>
            </el-form-item>
          </el-col>
         
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="汇报单编码" prop="fnumber" >
                <el-input v-model="reportData.fnumber" disabled></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item label="合格数量" prop="fgoodqty" >
                <el-input v-model="reportData.fgoodqty" type="number"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="6">
            <el-form-item label="不合格数量" prop="fbadqty" >
                <el-input v-model="reportData.fbadqty" type="number"></el-input>
            </el-form-item>
          </el-col>
           
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="生产订单ID" prop="fworkorderid" v-if="false">
                <el-input v-model="reportData.fworkorderid"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="生产订单行ID" prop="fworkorderentryid" v-if="false">
                <el-input v-model="reportData.fworkorderentryid"></el-input>
            </el-form-item>
          </el-col>
          

          <el-table border :data="entryList" v-loading="tableLoading" ref="iTable2" @row-click="entryhandleRowClick">
            <el-table-column align="center" type="selection" width="55"></el-table-column>
            <el-table-column label="订单ID" prop="fid" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="生产批号" prop="flot" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialnumber" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品" prop="fmaterialmodel" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="计量单位" prop="funitname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计产量" prop="fqty" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计完工时间" prop="fplanenddate" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="汇报数量" prop="fdoneqty" align="center" show-overflow-tooltip></el-table-column>
          </el-table>
        </el-row>

  </el-form> 
          </el-card>
          </span>
          <span  slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitReportDialog()">提交</el-button>
          <el-button @click="closeReportDialog(reportData)" type="danger">关闭</el-button>
          </span>
      </el-dialog>



      <el-dialog title="入库信息" :visible.sync="instoreDialog" width="100vw" v-if="instoreDialog" >
        <span>
          <el-card>
  <el-form label-width="100px" :model="instoreData" :rules="rules">
<el-row>
  <el-col :span="6">
            <el-form-item label="入库单编码" prop="fnumber" >
                <el-input v-model="instoreData.fnumber" disabled></el-input>
            </el-form-item>
          </el-col>
   <el-col :span="6">
                <el-form-item label="默认仓库:" prop="fwarehouseid">
                  <mdm-warehouse v-if="!isLoading" v-model="instoreData.fwarehouseid" ref="warehouse" :loadShow="instoreData.fwarehousename" @change="onWarehouseChange" ></mdm-warehouse>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="默认库区:" prop="fwareareaid">
                  <mdm-warearea v-if="!isLoading" v-model="instoreData.fwareareaid" ref="warearea" :loadShow="instoreData.fwareareaname"  @change="onWareareaChange"></mdm-warearea>
                </el-form-item>
              </el-col>
         <el-col :span="6">
                <el-form-item label="默认库位:" prop="flocationid">
                  <mdm-waresite v-if="!isLoading" v-model="instoreData.flocationid" ref="location" :loadShow="instoreData.flocationname" @change="onLocationChange"></mdm-waresite>
                </el-form-item>
              </el-col>
        </el-row>
        <el-row>
          
           <el-col :span="6">
            <el-form-item label="入库数量" prop="finstoreqty" >
                <el-input v-model="instoreData.fgoodqty" type="number"></el-input>
            </el-form-item>
          </el-col>
          
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="生产订单ID" prop="fworkorderid" v-if="false">
                <el-input v-model="instoreData.fworkorderid"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="生产订单行ID" prop="fworkorderentryid" v-if="false">
                <el-input v-model="instoreData.fworkorderentryid"></el-input>
            </el-form-item>
          </el-col>
          
          <el-table border :data="entryList" v-loading="tableLoading" ref="iTable2" @row-click="entryhandleRowClick">
            <el-table-column align="center" type="selection" width="55"></el-table-column>
            <el-table-column label="订单ID" prop="fid" align="center" show-overflow-tooltip v-if="false"></el-table-column>
            <el-table-column label="生产批号" prop="flot" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品名称" prop="fmaterialname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品编码" prop="fmaterialnumber" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="产品模型" prop="fmaterialmodel" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="计量单位" prop="funitname" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计产量" prop="fqty" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="预计完工时间" prop="fplanenddate" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="入库数量" prop="finstoreqty" align="center" show-overflow-tooltip></el-table-column>
          </el-table>
        </el-row>
  </el-form> 
          </el-card>
          </span>
          <span  slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitInstoreDialog()">提交</el-button>
          <el-button @click="closeInstoreDialog()" type="danger">关闭</el-button>
          </span>
      </el-dialog>

 <el-table border :data="dataList" v-loading="tableLoading" ref="iTable1" @row-click="handleRowClick">
            <el-table-column align="center" type="selection" width="55"></el-table-column>
            <el-table-column label="生产单编码" prop="fnumber" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="第三方id" prop="foid" align="center" show-overflow-tooltip v-if="false"></el-table-column>
            <el-table-column label="业务日期" prop="fbizdate" align="center" show-overflow-tooltip ></el-table-column>
             <el-table-column label="订单状态" prop="fstatus" align="center" show-overflow-tooltip>
                <template slot-scope="scope">
                <el-tag v-if="scope.row.fstatus =='暂存'" type="success">暂存</el-tag>
                <el-tag v-if="scope.row.fstatus =='审核'" type="primary">审核</el-tag>
                <el-tag v-if="scope.row.fstatus =='下达'" type="info">下达</el-tag>
                <el-tag v-if="scope.row.fstatus =='手动关闭'" type="danger">手动关闭</el-tag>
                <el-tag v-if="scope.row.fstatus =='自动关闭'" type="danger">自动关闭</el-tag>
              </template>
             </el-table-column>
            <el-table-column label="客户" prop="fcustomername" align="center" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="客户" prop="fcustomerid" align="center" show-overflow-tooltip v-if="false">
            </el-table-column>
            <el-table-column label="生产类型" prop="ftype" align="center">
 <template slot-scope="scope">
                <el-tag v-if="scope.row.ftype =='自制成品'" type="success">自制成品</el-tag>
                <el-tag v-if="scope.row.ftype =='自制半成品'" type="danger">自制半成品</el-tag>
                <el-tag v-if="scope.row.ftype =='受托加工'" type="primary">受托加工</el-tag>
                <el-tag v-if="scope.row.ftype =='研发'" type="primary">研发</el-tag>
                <el-tag v-if="scope.row.ftype =='其他'" type="primary">其他</el-tag>
              </template>

            </el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                <el-button type="text" @click.stop="openDetail(scope.row.fid)">详情</el-button>
                <el-button type="text" v-if="scope.row.fstatus =='暂存'" @click.stop="openEdit(scope.row.fid)">编辑</el-button>
              </template>
            </el-table-column>

          </el-table>
<el-pagination style="float:right; margin: 10px 0;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 15, 20, 50]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" prev-text="上一页" next-text="下一页" :total="totalRows">
          </el-pagination> 
     </div>
      </el-card>
         <workorderadd v-if="isShowMaterialAddEdit" :fid="fid" :operation="operation" :isview="isview" @close="closeAddEdit" @notRefresh="notRefresh"></workorderadd>
    </div>
</template>

<script>

import xuWorkOrderApi from "@/api/xuSimpleWork/WorkOrderApi"
import ReqMaterialApi from "@/api/xuSimpleWork/ReqMaterialApi"
import ReportApi from "@/api/xuSimpleWork/ReportApi"
import InStoreApi from "@/api/xuSimpleWork/InStoreApi"
import wareHouseApi from '@/api/ware/WareHouseApi'
import wareSiteApi from '@/api/ware/WareSiteApi'
import WareAreaApi from '@/api/ware/WareAreaApi'
import {workorderadd} from "./components/workOrder_add.vue"
export default 
  {
     name: 'xuWorkOrder',
     components: {
       workorderadd: resolve => require(['./components/workOrder_add'], resolve),
    },
     data(){
        return {
        value1:'',
        fnumber:'',
        isview: false,
        tableLoading: false,
        dataList: [],
        entryList: [],
        page: 1, //当前页面
        pageSize: 10, // 当前页数
        totalRows: 0, // 总条数
        services: new xuWorkOrderApi(),
        isShowMaterialAddEdit: false,
        dialogVisible : false,
        reqMaterialDialog: false,
        instoreDialog: false,
        reportDialog : false,
        fclosereason : '',
        materialData:{},
        reportData:{},
        instoreData:{},
        warehouseData: [],
        locationData: [],
        wareareaData: [],
        isLoading: true,
        unitText:'',
        rules:{
        freqqty: [{ required: true, message: '领料数量不能为空！'}],
        fgoodqty: [{ required: true, message: '合格数量不能为空！'}],
        fbadqty: [{ required: true, message: '不合格数量不能为空！'}],
        freqlot: [{ required: true, message: '原料批号不能为空' }],
        fmaterialid: [{ required: true, message: '原料不能为空'}],
        fmachineid: [{ required: true, message: '设备不能为空'}],
        fmodid: [{ required: true, message: '模具不能为空'}],
        fwarehouseid: [{ required: true, message: '仓库不能为空'}],
        finstoreqty: [{ required: true, message: '入库数量不能为空'}],
    },
        MaterialF7Param :{
            selectId:'fid',
            selectUrl:'/tie-mdm/material/queryListPage',
            selectTreeField:['fgroupid'],
            selectTreeUrl:'/tie-mdm/materialGroup/queryGroupTree',
            selectShow:{spt:'',field:['fname']},
            column:[
              {lable:'编号',prop:'fnumber',isFilter:true,filterField:'fnumber'},
              
              {lable:'名称',prop:'fname',isFilter:true,filterField:'fname'}
            ,{lable:'规格型号',prop:'fmodel',isFilter:true,filterField:'fmodel'}
            ,{lable:'简称',prop:'fsimplename',isFilter:true,filterField:'fsimplename'}
            ],
            defaultFilter:[{field:'fstatus',value:"USED"}]
        },
        modF7Param :{
            selectId:'fid',
            selectUrl:'/tie-eqp/mould/queryListPage',
            selectTreeField:['fgroupid'],
            selectTreeUrl:'/tie-eqp/mouldgroup/queryGroupTree',
            selectShow:{spt:'',field:['fnumber']},
            column:[
              {lable:'编号',prop:'fnumber',isFilter:true,filterField:'fnumber'},
              
               {lable:'模穴数',prop:'fcavity',isFilter:true,filterField:'fcavity'},
            ],
            
        },
        machineF7Param :{
            selectId:'fid',
            selectUrl:'/tie-eqp/equipment/queryListPage',
            selectTreeField:['fgroupid'],
            selectTreeUrl:'/tie-eqp/equipmentGroup/queryGroupTree',
            selectShow:{spt:'',field:['fnumber']},
            column:[
              {lable:'编码',prop:'fnumber',isFilter:true,filterField:'fnumber'},
              
              {lable:'名称',prop:'fname',isFilter:false,filterField:'fname'}
            ,{lable:'规格型号',prop:'fmodel',isFilter:false,filterField:'fmodel'}
            ,{lable:'车间',prop:'fuseaddress',isFilter:true,filterField:'fuseaddress'}
            ],
        },
         }
     },
async created () {
  this.isLoading = true
  this.getData();
  this.isLoading = false
  },
    methods :{
    getData() {
      this.tableLoading = true
      let data = {
        fstartdate: this.value1[0],
        fenddate: this.value1[1],
        fnumber: this.fnumber,
        pageSize: this.pageSize,
        page: this.page,
      }
      this.services.queryListPage(data).then(res => {
        this.dataList = res.data.rows
        this.page = res.data.page
        this.pageSize = res.data.pageSize
        this.totalRows = res.data.totalRows
        this.tableLoading = false
      })
    },
     openAdd () {
      this.fid = null
      this.isview = false
      this.operation = 'add'
      this.isShowMaterialAddEdit = true
    },
     openEdit (id) {
      this.fid = id
      this.isview = false
      this.operation = 'edit'
      this.isShowMaterialAddEdit = true
    },
    openDetail (id) {
      this.fid = id
      this.isview = true
      // this.isShowDetail = true
      this.operation = 'view'
      this.isShowMaterialAddEdit = true
    },
    batchZc () {
      var fids = this.getSelectIdByTable();
      if (fids.length == 0) {
        this.$message.error('未选中数据!')
      } else {
        const loading = this.$loading({
          lock: true,
          text: `批量操作中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.services.batchChangeZc(fids).then(res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }).catch(e => {
          loading.close();
        })
      }
      this.getData()
    },
    batchSh () {
      var fids = this.getSelectIdByTable();
      if (fids.length == 0) {
        this.$message.error('未选中数据!')
      } else {
        const loading = this.$loading({
          lock: true,
          text: `批量操作中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.services.batchChangeSh(fids).then(res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }).catch(e => {
          loading.close();
        })
      }
      this.getData()
    },
    batchXd () {
      var fids = this.getSelectIdByTable();
      if (fids.length == 0) {
        this.$message.error('未选中数据!')
      } else {
        const loading = this.$loading({
          lock: true,
          text: `批量操作中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.services.batchChangeXd(fids).then(res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }).catch(e => {
          loading.close();
        })
      }
      this.getData()
    },
    remove(){
      var fids = this.getSelectIdByTable();
      if (fids.length == 0) {
        this.$message.error('未选中数据!')
      } 
      else {
        const loading = this.$loading({
          lock: true,
          text: `批量操作中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.services.removeByObject({ "ids": fids}).then(res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }).catch(e => {
          loading.close();
        })
      }
    },
    submitclosereason(){
      var fid = this.getSelectIdByTable()
      var fclosereason = this.fclosereason
      if(fclosereason!=''){
 const loading = this.$loading({
          lock: true,
          text: `提交中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
  this.services.submitCloseReason({"ids": fid,"closeReason":fclosereason}).then(
res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }
  ).catch(e => {
          loading.close();
        })
        
        this.getData();
        this.dialogVisible = false;
      }
     else{
        this.$message.error('未填写关闭原因!')
     }
    },
    onF7ModSelected(row){
        this.reportData.fmodcavity = row.fcavity;
      },
      onF7MachineSelected(row){
        this.reportData.fmachinename = row.fname;
      },
    ReqMaterial(){
    var fid = this.getSelectIdByTable()
    this.initSelect();
    this.materialData.fworkorderid = fid[0];
    
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){
      this.reqMaterialDialog = true;
      this.$NumRuleUtil.getNumber(this, "cn.hxlc.tie.demo.modular.jf.model.result.XjfReqMaterialResult", null, 'materialData', 'fnumberAnable', 'fnumber');
      this.services.queryEntryDetail({"fid": fid[0]}).then(res => {
        this.entryList = res.data
        this.tableLoading = false
      })
      }
      else{
        this.$message.error('每次仅可以对一条订单进行领料操作!')
      }
    },
    reportMaterial(){
    var fid = this.getSelectIdByTable()
   
    this.initSelect();
    this.reportData.fworkorderid = fid[0];
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){
        this.reportDialog = true;
        this.$NumRuleUtil.getNumber(this, "cn.hxlc.tie.demo.modular.jf.model.result.XjfreportResult", null, 'reportData', 'fnumberAnable', 'fnumber');
        this.services.queryEntryDetail({"fid": fid[0]}).then(res => {
        this.entryList = res.data
        this.tableLoading = false
      })
      }
      else{
        this.$message.error('每次仅可以对一条订单进行汇报操作!')
      }
    },
 instoreMaterial(){
    var fid = this.getSelectIdByTable()
    
    this.initSelect();
    this.instoreData.fworkorderid = fid[0];
 
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){
      this.$NumRuleUtil.getNumber(this, "cn.hxlc.tie.demo.modular.jf.model.result.XjfinstoreResult", null, 'instoreData', 'fnumberAnable', 'fnumber');
      this.services.queryEntryDetail({"fid": fid[0]}).then(res => {
        this.entryList = res.data
        this.tableLoading = false
      })
      
      this.instoreDialog = true;
      }
      else{
        this.$message.error('每次仅可以对一条订单进行入库操作!')
      }
    },

async initSelect () {
      let wareHouseHttp = new wareHouseApi();
      let warehouseData = await wareHouseHttp.queryListPage();
      this.warehouseData = warehouseData.data.rows;
      let wareSiteHttp = new wareSiteApi();
      let locationData = await wareSiteHttp.queryListPage();
      this.locationData = locationData.data.rows;
      let WareAreaHttp = new WareAreaApi();
      let wareareaData = await WareAreaHttp.queryListPage();
      this.wareareaData = wareareaData.data.rows;
    },

    closereason(){
      var fid = this.getSelectIdByTable()
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else{
      this.dialogVisible = true;
      }
      
    },

    closeReqMaterialDialog(){
        this.materialData={}
        this.reqMaterialDialog = false,           
      this.getData();
      
    },
    closeReportDialog(){
      this.reportData={}
      this.reportDialog = false,
      this.getData();
      
    },
    closeInstoreDialog(){
      this.instoreData={}
      this.instoreDialog = false,
    
      this.getData();
      
    },
    closeDialog(){
      this.materialData={}
      this.dialogVisible = false;
      this.getData();
    },
    closeAddEdit () {
      this.isShowMaterialAddEdit = false
    
      this.getData()
    },
    notRefresh () {
      this.isShowMaterialAddEdit = false

    },
    getSelectIdByTable () {
      var batchChoose = this.$refs.iTable1.selection;
      var fids = [];
      for (var i = 0; i < batchChoose.length; i++) {
        fids[i] = batchChoose[i].fid;
      }
      return fids;
    },
    getSelectIdByEntryTable () {
      var batchChoose = this.$refs.iTable2.selection;
      var fids = [];
      for (var i = 0; i < batchChoose.length; i++) {
        fids[i] = batchChoose[i].fid;
      }
      return fids;
    },
    searchData () {
      this.page = 1
    
      this.getData()
    },
    clearData () {
     this.value1 = '',
     this.fnumber = ''
    },
    handleRowClick (row, column, event) {
      this.$refs.iTable1.toggleRowSelection(row)
    },
    entryhandleRowClick (row) {
      this.$refs.iTable2.toggleRowSelection(row)
    },
    handleCurrentChange (page) {
      this.page = page
      this.getData()
    },
    handleSizeChange (pageSize) {
      this.pageSize = pageSize
      this.getData()
    },
    submitReqMaterialDialog(){
      let http = new ReqMaterialApi()
      var fid = this.getSelectIdByEntryTable()
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){
      this.materialData.fworkorderentrtyid = fid[0];
      const loading = this.$loading({
          lock: true,
          text: `提交中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        http.submitReqMaterialDialog(this.materialData).then(
        res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }
  ).catch(e => {
          loading.close();
        })
        this.closeReqMaterialDialog()
        this.getData();
      }
      else{
        this.$message.error('一次只允许操作一条数据!')
      }
      
      },

      submitReportDialog(){
      let http = new ReportApi()
      var fid = this.getSelectIdByEntryTable()
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){
      this.reportData.fworkorderentrtyid = fid[0];
      const loading = this.$loading({
          lock: true,
          text: `提交中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        http.submitReportDialog(this.reportData).then(
        res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }
  ).catch(e => {
          loading.close();
        })
          this.closeReportDialog()
      this.getData()
      }
      else{
        this.$message.error('一次只允许操作一条数据!')
      }
      
      },
      submitInstoreDialog(){
      let http = new InStoreApi()
      var fid = this.getSelectIdByEntryTable()
      console.log(this.instoreData);
      if(fid.length==0){
        this.$message.error('未选中数据!')
      }
      else if(fid.length==1){

      this.instoreData.fworkorderentrtyid = fid[0];
      const loading = this.$loading({
          lock: true,
          text: `提交中，请耐心等待.....`,
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        http.submitInStoreDialog(this.instoreData).then(
        res => {
          this.$tie.showSuccess(res.message)
          loading.close();
          this.getData();
        }
  ).catch(e => {
          loading.close();
        })
        this.closeInstoreDialog()
        this.getData()
      }
         else{
         this.$message.error('一次只允许操作一条数据!')
      }
      },
      
 onWarehouseChange (row) {
      //先设置默认值，仓库改变时，设置自身值但不触发值改变事件
      let isClean = this.$tie.isEmpty(row);
      this.instoreData.fwarehousename = null
      this.instoreData.fwareareaname = null
      this.instoreData.flocationname = null
      this.$refs.warehouse.defaultSelect({ fid: null, fname: null, isChange: "0" })
      this.$refs.warearea.defaultSelect({ fid: null, fname: null, isChange: "0" })
      this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })
      if (!isClean) {
        //有值时设置自身默认值，设置库区过滤条件
        this.instoreData.fwarehousename = row.fname
        this.$refs.warehouse.defaultSelect({ fid: row.fid, fname: row.fname, isChange: "0" })
        this.$refs.warearea.refresh([{ field: 'fwarehouseid', value: row.fid }])
        this.$refs.location.refresh([{ field: null, value: null }])
      } else {
        //没值时就是清空，清空设置自身为空，库区为空，库位为空，库区和库位的过滤条件为空
        this.instoreData.fwarehousename = null
        this.instoreData.fwareareaname = null
        this.instoreData.flocationname = null
        this.$refs.warehouse.defaultSelect({ fid: null, fname: null, isChange: "0" })
        this.$refs.warearea.defaultSelect({ fid: null, fname: null, isChange: "0" })
        this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })

        this.$refs.warearea.refresh([{ field: null, value: null }])
        this.$refs.location.refresh([{ field: null, value: null }])
      }
    },
    onWareareaChange (row) {
    //先设置默认值，库区改变时设置自身值但不触发值改变事件，设置仓库值但不触发值改变事件
      let isClean = this.$tie.isEmpty(row);
      // this.materialData.fwarehousename = null
      this.instoreData.fwareareaname = null
      this.instoreData.flocationname = null
    // this.$refs.warehouse.defaultSelect({fid:null,fname:null,isChange:"0"})
      this.$refs.warearea.defaultSelect({ fid: null, fname: null, isChange: "0" })
      this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })
      if (!isClean) {
    //有值时设置仓库、自身默认值，设置库区过滤条件
        this.instoreData.fwarehousename = row.fwarehousename
        this.instoreData.fwareareaname = row.fname
        this.$refs.warehouse.defaultSelect({ fid: row.fwarehouseid, fname: row.fwarehousename, isChange: "0" })
        this.$refs.warearea.defaultSelect({ fid: row.fid, fname: row.fname, isChange: "0" })
        this.$refs.warehouse.refresh([{ field: null, value: null }])
        this.$refs.warearea.refresh([{ field: 'fwarehouseid', value: row.fwarehouseid }])
        this.$refs.location.refresh([{ field: 'fwareareaid', value: row.fid }])
      } else {
    //没值时就是清空，清空设置自身值为空，库位为空，库位的过滤条件为空
        this.instoreData.fwareareaname = null
        this.instoreData.flocationname = null
        this.$refs.warearea.defaultSelect({ fid: null, fname: null, isChange: "0" })
        this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })
        this.$refs.location.refresh([{ field: null, value: null }])
      }
    },
    onLocationChange (row) {
      //先设置默认值，库位改变时设置自身值、库区值、仓库值
      let isClean = this.$tie.isEmpty(row);
      // this.materialData.fwarehousename = null
      // this.materialData.fwareareaname = null
      this.instoreData.flocationname = null
      // this.$refs.warehouse.defaultSelect({fid:null,fname:null,isChange:"0"})
      // this.$refs.warearea.defaultSelect({fid:null,fname:null,isChange:"0"})
      this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })
      if (!isClean) {
        //有值时设置仓库、库区、自身默认值，不触发值更新事件，设置仓库、库区、库位过滤条件
        this.instoreData.fwarehousename = row.fwarehousename
        this.instoreData.fwareareaname = row.fwareareaname
        this.instoreData.flocationname = row.fname
        this.$refs.warehouse.defaultSelect({ fid: row.fwarehouseid, fname: row.fwarehousename, isChange: "0" })
        this.$refs.warearea.defaultSelect({ fid: row.fwareareaid, fname: row.fwareareaname, isChange: "0" })
        this.$refs.location.defaultSelect({ fid: row.fid, fname: row.fname, isChange: "0" })
        this.$refs.warehouse.refresh([{ field: null, value: null }])
        this.$refs.warearea.refresh([{ field: 'fwarehouseid', value: row.fwarehouseid }])
        this.$refs.location.refresh([{ field: 'fwareareaid', value: row.fwareareaid }])
      } else {
        //没值时就是清空，清空自身值为空，库区为空，仓库为空，自身、库区、仓库的过滤条件为空
        // this.materialData.fwarehousename = null
        // this.materialData.fwareareaname = null
        this.instoreData.flocationname = null
        // this.$refs.warehouse.defaultSelect({fid:null,fname:null,isChange:"0"})
        // this.$refs.warearea.defaultSelect({fid:null,fname:null,isChange:"0"})
        this.$refs.location.defaultSelect({ fid: null, fname: null, isChange: "0" })
        // this.$refs.warehouse.refresh([{field:null,value:null}])
        // this.$refs.warearea.refresh([{field:null,value:null}])
        // this.$refs.location.refresh([{field:null,value:null}])
      }
    },

     }
  }
</script>
<style scoped lang="scss" >
/deep/.tree-scroll {
  height: 93%;
  overflow: scroll;
}
/deep/ .el-card__body {
  height: 100%;
}
</style>